package com.example.goodsserver.manager;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.goodsserver.entity.Collection;
import com.example.goodsserver.mapper.CollectionMapper;
import com.example.goodsserver.vo.CollectionVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CollectionManager {
    @Autowired
    private CollectionMapper collectionMapper;
    public void insertCollection(Collection collection){
        collectionMapper.insert(collection);
    }

    public void deleteCollection(String id){
        collectionMapper.deleteById(id);
    }

    public void updateCollection(Collection collection){
        collectionMapper.updateById(collection);
    }
    public List<CollectionVO> listCollection(String userId){
        return collectionMapper.pageCollectionByUserId(userId);
    }


    public Collection getCollection(String id) {
        return collectionMapper.selectById(id);
    }

    public Collection getCollectionExist(String userId, String goodsId) {
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("user_id", userId);
        queryWrapper.eq("goods_id", goodsId);
        return collectionMapper.selectOne(queryWrapper);
    }
}
